<template>
  <div class="dashboard-container">
    <div class="grid-container">
      <!-- 其他网格项... -->
      
      <!-- 课堂质量实时反馈网格项 -->
      <div class="grid-item" @click="handleFeedbackClick">
        <div class="grid-content">
          <img src="@/assets/svgs/feedback.svg" alt="反馈" class="grid-icon" />
          <div class="grid-text">
            <div class="grid-title">课堂质量实时反馈</div>
            <div class="grid-stats">
              已完成 {{ feedbackStats.completed }}/{{ feedbackStats.total }}
            </div>
          </div>
        </div>
      </div>
      
      <!-- 其他网格项... -->
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { getFeedbackStats } from '@/api/feedback';

const router = useRouter();
const feedbackStats = ref({
  total: 0,
  completed: 0
});

// 获取问卷统计数据
const fetchFeedbackStats = async () => {
  try {
    const result = await getFeedbackStats();
    console.log('问卷统计数据:', result);

    if (result.code === 0) {
      feedbackStats.value = {
        total: result.data.total || 0,
        completed: result.data.completed || 0
      };
      console.log('更新后的统计数据:', feedbackStats.value);
    } else {
      console.error('获取统计数据失败:', result.message);
    }
  } catch (error) {
    console.error('获取问卷统计失败:', error);
  }
};

// 处理点击事件
const handleFeedbackClick = () => {
  router.push('/student/feedback/card');
};

onMounted(async () => {
  console.log('组件挂载，开始获取统计数据'); // 添加日志
  await fetchFeedbackStats();
});
</script>

<style scoped>
.dashboard-container {
  padding: 20px;
}

.grid-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.grid-item {
  background-color: white;
  border-radius: 8px;
  padding: 20px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.grid-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.grid-content {
  display: flex;
  align-items: center;
  gap: 16px;
}

.grid-icon {
  width: 40px;
  height: 40px;
}

.grid-text {
  flex: 1;
}

.grid-title {
  font-size: 16px;
  font-weight: bold;
  color: #333;
  margin-bottom: 4px;
}

.grid-stats {
  font-size: 14px;
  color: #666;
}
</style> 